
import Http from '../../utils/http_promise';

Page({

  data: {
    houses:[],
    page:1,
    isLoading:false,
    isFinish:false
  },

  onLoad: function () {
    this.getHouse();
    this.search();
  },

  search(){
    let url = "house/search";
    Http.request({
      url,
      method:'POST',
      data:{words:'测试'}
    })
    .then(res=>{
       console.log(res);
    })
  },

  detail(e){

     let id = e.currentTarget.dataset.id;
     wx.navigateTo({
       url: '/pages/detail/detail?id='+id
     })
  
  },
  
   getHouse(){

    wx.showNavigationBarLoading();

     let url = 'house/list?page='+this.data.page;

     this.data.isLoading = true;

     Http.request({url}).then(res=>{

      wx.hideNavigationBarLoading();
        
        this.data.isLoading = false;
        if(res.data.length==0) this.data.isFinish = true;

        let tmpArr = [...this.data.houses];

        tmpArr = tmpArr.concat(res.data);
        
        this.setData({
          houses:tmpArr
        })

        this.data.page+=1;
     })
     

  },

  getMore(){

    if(this.data.isLoading || this.data.isFinish){
      return false;
    }

    this.getHouse();

  },

  onReachBottom: function () {
    this.getMore();
  }
  
  
})

